using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;

namespace HandyIRCChat
{
    public class OptionsDescriptorWrapper : ICustomTypeDescriptor
    {
		private Options optionsInstance;

        private PropertyDescriptorCollection propertyDescriptorCollection;

		public OptionsDescriptorWrapper(Options opt)
		{
            optionsInstance = opt;

            propertyDescriptorCollection = new PropertyDescriptorCollection(null);

            PropertyDescriptorCollection propColl = TypeDescriptor.GetProperties(optionsInstance);
            foreach (PropertyDescriptor pd in propColl)
            {
                OptionsPropertyDescriptorWrapper pdw = 
                    new OptionsPropertyDescriptorWrapper(optionsInstance, pd);

                if (!pdw.IsHidden)
                {
                    propertyDescriptorCollection.Add(pdw);
                }
            }
        }

        public Options OptionsInstance
        {
            get
            {
                return optionsInstance;
            }
        }

		#region ICustomTypeDescriptor implementation

		AttributeCollection ICustomTypeDescriptor.GetAttributes()
		{
			return new AttributeCollection(null);
		}

		string ICustomTypeDescriptor.GetClassName()
		{
            return optionsInstance.GetType().Name;
		}

		string ICustomTypeDescriptor.GetComponentName()
		{
			return null;
		}

		TypeConverter ICustomTypeDescriptor.GetConverter() 
		{
			return null;
		}

		EventDescriptor ICustomTypeDescriptor.GetDefaultEvent() 
		{
			return null;
		}

		PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty() 
		{
			return null;
		}

		object ICustomTypeDescriptor.GetEditor(Type editorBaseType) 
		{
			return null;
		}

		EventDescriptorCollection ICustomTypeDescriptor.GetEvents() 
		{
			return new EventDescriptorCollection(null);
		}

		EventDescriptorCollection ICustomTypeDescriptor.GetEvents(Attribute[] attributes) 
		{
			return new EventDescriptorCollection(null);
		}

		PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties() 
		{
			return propertyDescriptorCollection;
		}

		PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes) 
		{
            return propertyDescriptorCollection;
        }

		object ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor pd) 
		{
			return this;
		}

		#endregion
    }
}
